package cn.edu.lzu.unitweb.controller;

import cn.edu.lzu.common.assist.DataPage;
import cn.edu.lzu.common.assist.ResponseResult;
import cn.edu.lzu.entity.Examiner;
import cn.edu.lzu.entity.RadiologyExamineItem;
import cn.edu.lzu.service.RadiologyExamineItemService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.support.DefaultSubjectContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.List;

/**
 * @PackageName: cn.edu.lzu.unitweb.controller
 * @ClassName: RadiologyExamineItemController
 * @Description: TODO 对放射类检查项目的操作接口
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/3/23 21:01
 * @Version: 1.0
 */
@Controller
public class RadiologyExamineItemController {
    @Resource
    private RadiologyExamineItemService radiologyExamineItemService;

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 获取本单位一页放射科检查项目的数据
     * @Date: 2020/3/23 22:25
     * @Param: [currentPageNum, pageSize]
     * @Return: cn.edu.lzu.common.assist.DataPage
     **/
    @ResponseBody
    @RequestMapping("/getRadExamineItems")
    public DataPage getRadExamineItems(int currentPageNum, int pageSize){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        DataPage dataPage=radiologyExamineItemService.getRadiologyExamineItemList(examiner.getUnitId(), currentPageNum, pageSize);
        return dataPage;

    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 添加新的放射类检查项目接口
     * @Date: 2020/3/23 23:00
     * @Param: [radiologyExamineItem]
     * @Return: cn.edu.lzu.common.assist.ResponseResult
     **/
    @ResponseBody
    @RequestMapping("/submitAddRadExamineItem")
    public ResponseResult submitAddRadExamineItem(RadiologyExamineItem radiologyExamineItem){
        System.out.println(radiologyExamineItem);
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        radiologyExamineItem.setUnitId(examiner.getUnitId());
        ResponseResult responseResult=radiologyExamineItemService.addRadExamineItem(radiologyExamineItem);
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/deleteRadItemById")
    public ResponseResult deleteRadItemById(Integer examineItemId){
        ResponseResult responseResult=radiologyExamineItemService.deleteRadItemById(examineItemId);
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/fuzzySearchRadItem")
    public DataPage  fuzzySearchRadItem(int searchType, String searchInput, int currentPageNum, int pageSize){
        System.out.println("searchType:"+searchType+"\t"+"searchInput:"+searchInput);
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        DataPage dataPage=radiologyExamineItemService.getFuzzySearchRadItem(searchType, searchInput, examiner.getUnitId(), currentPageNum, pageSize);
        return dataPage;
    }

    @ResponseBody
    @RequestMapping("/getAllRadItems")
    public List<RadiologyExamineItem> getAllRadItems(){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        List<RadiologyExamineItem> radiologyExamineItemList=radiologyExamineItemService.getAllRadItems(examiner.getUnitId());
        return radiologyExamineItemList;
    }



}
